/*
 * Copyright (c) 2018.
 * This file was written by Fancyears·Milos·Malvis @connor. Any question/bug you can't post to 1243093366@qq.com.
 * ALL RIGHTS RESERVED.
 */
package org.fancyears.frame;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import org.fancyears.commom.InitializationWithSkin;
import org.fancyears.iservice.impl.CheckBoxEventService;
import org.fancyears.renderer.jtable.TableDataController;
import org.fancyears.renderer.jtable.HyperRenderer;

/**
 * @author: Fancyears·Milos·Malvis
 * @CreateDate: 2018年12月4日 上午11:33:02
 * @Description:
 */

public class ZFrame extends InitializationWithSkin {

	public ZFrame() {
		setCustomSkin(false);
	}

	@Override
	public boolean init() throws Exception {
		jf = new JFrame("Hello");
		jf.setSize(200, 300);
		return true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.fancyears.commom.Initializer#createContents()
	 */
	@Override
	public void createContents() throws Exception {
		JTable jTable = new JTable();
		jTable.setUI(new JTable().getUI());
		TableDataController model = new TableDataController();
		model.setTable(jTable);
		jTable.setModel(model);
		jTable.setVisible(true);

		JScrollPane scrollPane = new JScrollPane(jTable);
		scrollPane.setVisible(true);
		scrollPane.setViewportView(jTable);
		scrollPane.setAutoscrolls(true);
		scrollPane.setWheelScrollingEnabled(true);
		jf.add(scrollPane);
		for (int i = 0; i < 10; i++) {
			model.addColumn("Title" + i);
		}
		JComboBox<String> cb = new JComboBox<>();
		cb.addItem("1");
		cb.addItem("2");
		cb.addItem("3");
		cb.addItem("4");

		JCheckBox box = new JCheckBox();
		JButton jb = new JButton();
		jb.setSize(new Dimension(50, 50));
		jb.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				System.out.println("Hello");
			}
		});
		jTable.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(cb));
		jTable.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(box));
		model.getService().put(1, new CheckBoxEventService());
		// // 渲染第三列
		// jTable.getColumnModel().getColumn(2).setCellRenderer(new ButtonRenderer(jb));
		// jTable.getColumnModel().getColumn(2).setCellEditor(new ButtonRenderer(jb));
		// 渲染第四列的单元格
		jTable.getColumnModel().getColumn(3).setCellRenderer(new HyperRenderer(jTable));
		jTable.getColumnModel().getColumn(3).setCellEditor(new HyperRenderer(jTable));
		for (int j = 0; j < 100; j++) {
			Vector<Object> v = new Vector<>();
			for (int i = 0; i < 10; i++) {
				if (1 == i) {
					v.add(true);
				} else {
					v.add("Data" + i + "_" + j);
				}
			}
			model.addRow(v);
		}
	}

	@Override
	public void addSkin() throws Exception {
	}

}
